<template>
	<view>
		<cu-custom bgColor="bg-white" :isBack="true">
			<block slot="backText"></block>
			<block slot="content">对外信息显示</block>
		</cu-custom>
		
		<mpvue-city-picker
			:themeColor="cityPicker.themeColor"
			ref="mpvueCityPicker"
			:pickerValueDefault="cityPicker.cityPickerValue"
			@onCancel="onCancel"
			@onConfirm="onConfirm"
		></mpvue-city-picker>
		<view class="qui-cells bg-white mb30">
			<view class="qui-cells-title">
				<text class="fs30 fw600 text-default">以下信息将对外部显示</text>
			</view>
			<view class="qui-cells-tips">
				<view class="qui-cell">
					<view class="cell-label">
						<text class="fs28 text-default">公司名称</text>
					</view>
					<view class="cell-bd tr">
						<text class="text-muted" v-text="YMTCardSetModel.Company"></text>
					</view>
				</view>
				<view class="qui-cell">
					<view class="cell-label">
						<text class="fs28 text-default">名字</text>
					</view>
					<view class="cell-bd tr">
						<text class="text-muted" v-text="YMTCardSetModel.Name"></text>
					</view>
				</view>
				<view class="qui-cell">
					<view class="cell-label">
						<text class="fs28 text-default">手机</text>
					</view>
					<view class="cell-bd tr">
						<switch :checked="YMTCardSetModel.IsShowPhone==1?true:false" @change="YMTCardSetModel.IsShowPhone = YMTCardSetModel.IsShowPhone==0?1:0" :class="YMTCardSetModel.IsShowPhone==1?'checked':''"/>
					</view>
				</view>
				
				
				<view class="qui-cell" v-if="YMTCardSetModel.IsShowPhone==1">
					<view class="cell-bd">
						<input type="text" class="cu-input fw600 fs26" placeholder="填写手机号" placeholder-class="fw500" v-model="YMTCardSetModel.Phone">
					</view>
				</view>
				
				
				<view class="qui-cell">
					<view class="cell-label">
						<text class="fs28 text-default">邮箱</text>
					</view>
					<view class="cell-bd tr">
						<switch :checked="YMTCardSetModel.IsShowEmail==1" @change="YMTCardSetModel.IsShowEmail = YMTCardSetModel.IsShowEmail==0?1:0" :class="YMTCardSetModel.IsShowEmail==1?'checked':''"/>
					</view>
				</view>
				<view class="qui-cell" v-if="YMTCardSetModel.IsShowEmail==1">
					<view class="cell-bd">
						<input type="text" class="cu-input fw600 fs26" placeholder="请填写邮箱号" placeholder-class="fw500"  v-model="YMTCardSetModel.Email">
					</view>
				</view>
				<view class="qui-cell">
					<view class="cell-label">
						<text class="fs28 text-default">地址</text>
					</view>
					<view class="cell-bd tr">
						<switch :checked="YMTCardSetModel.IsShowAddress==1" @change="YMTCardSetModel.IsShowAddress = YMTCardSetModel.IsShowAddress==1?0:1" :class="YMTCardSetModel.IsShowAddress==1?'checked':''"/>
					</view>
				</view>
				<view v-if="YMTCardSetModel.IsShowAddress==1">
					<view class="qui-cell">
						<view class="cell-bd" @tap="chooseCity" >
							{{YMTCardSetModel.Province==''?'请选择省市区':YMTCardSetModel.Province + ' ' + YMTCardSetModel.City + ' ' + YMTCardSetModel.Area}}
						</view>
					</view>
					<view class="qui-cell">
						<view class="cell-bd">
							<textarea value="" placeholder="请输入详细地址:如道路、门牌号" placeholder-class="text-muted fs24" style="height: 200rpx;" v-model="YMTCardSetModel.Address"/>	
						</view>
					</view>
				</view>
				
				
			</view>
		</view>
		<view class="uni-btns_fixed-bottom">
			<view class="uni-btn bg-main" style="border-radius: 0;" @tap="save">
				<text class="fs28 fw600 text-white">保存</text>
			</view>
		</view>
	</view>
	
	
</template>

<script>
	import base from 'utils/base.js';
	import tools from 'utils/tools.js';
	import mpvueCityPicker from '@/common/components/mpvue-citypicker/mpvueCityPicker'
	export default {
		components: {
			mpvueCityPicker
		},
		data(){
			return {
				companyName:"",
				nickName:"",
				
				cityPicker:{
					cityPickerValue: [0, 0, 1],
					themeColor: '#007AFF',
					region:{label:"请点击选择所在地区",value:[],cityCode:""}
				},
				YMTCardSetModel:{
					TemplateID:0,
					BackGroundCode:"",
					CssCode:"0",
					DIYBackGroundImage:"",
					Company:"",
					Name:"",
					IsShowAddress:0,
					Province:"",
					City:"",
					Area:"",
					Address:"",
					IsShowEmail:0,
					Email:"",
					IsShowPhone:0,
					Phone:"",
					ProvinceCode:"",
					CityCode:"",
					AreaCode:""
					
					
				}
			}
		},
		methods:{
			chooseCity() {
				this.$refs.mpvueCityPicker.show();
			},
			onConfirm(e) {
				this.cityPicker.region = e;
				this.cityPicker.cityPickerValue = e.value;
				this.YMTCardSetModel.Province = e.province;
				this.YMTCardSetModel.ProvinceCode = e.provinceCode;
				this.YMTCardSetModel.City = e.city;
				this.YMTCardSetModel.CityCode = e.cityCode;
				this.YMTCardSetModel.Area = e.area;
				this.YMTCardSetModel.AreaCode = e.areaCode;
				
			},
			navCard(){
				uni.redirectTo({
					url:'/pages/my/sales/card'
				})
			},
			changeDefault(e) {
				
			},
		
			onCancel(e) {},
			
			GetMyCard: function() {
				let currentPage = this;
			
				let globalData = getApp().globalData;
			
				let params = {
					type: 'GET',
					url: '/api/ScanCodeDistribution/GetMyCard',
					data: {},
					sCallback: function(response) {
						if (response.IsSuccess) {
							let card = response.Data;
							if(card!=null)
							{
								currentPage.YMTCardSetModel=card;
							}
							
						
						}
					}
				};
				base.request(params);
			},
			save: function() {
				let currentPage = this;
				var ymtCardSetModel = currentPage.YMTCardSetModel;
				
				if (ymtCardSetModel.IsShowPhone==1 && !tools.IsPhone(ymtCardSetModel.Phone)) {
					tools.showToast('请输入正确的手机号码');
					return;
				}
				if (ymtCardSetModel.IsShowEmail == 1 && !tools.IsEmail(ymtCardSetModel.Email)) {
					tools.showToast('请输入正确的邮箱地址');
					return;
				}
				if (ymtCardSetModel.IsShowAddress == 1 && ymtCardSetModel.Area=="") {
					tools.showToast('请选择省市区');
					return;
				}
				if (ymtCardSetModel.IsShowAddress == 1 && ymtCardSetModel.Address.trim()=="") {
					tools.showToast('请填写详细地址');
					return;
				}
				let url = '/api/ScanCodeDistribution/AddCardInfo';
			
				let params = {
					type: 'POST',
					url: url,
					data: ymtCardSetModel,
					sCallback: function(response) {
						if (response.IsSuccess) {
							uni.navigateBack({
								delta: 1
							});
						}
					}
				};
				base.request(params);
			}
		},
		mounted() {
			let currentPage = this;
			let globalData = getApp().globalData;
			currentPage.YMTCardSetModel.Company=globalData.Customer.Name;
			currentPage.YMTCardSetModel.Name=globalData.UserInfo.NickName;
			currentPage.GetMyCard();
		}
	}
</script>

<style>
</style>
